package com.zee.example;

import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zee.recyclerview.HintText;
import com.zee.recyclerview.IRecyclerViewRefreshView;
import com.zee.utils.UIUtils;

public class DRLoadingFreshViewRecyclerView implements IRecyclerViewRefreshView {
    private AnimationDrawable animationDrawable;
    private TextView loadTextView;
    private ImageView loadImage;

    @Override
    public int getLayoutID() {
        return R.layout.layout_dr_refresh;
    }

    @Override
    public void initViews(LinearLayout view) {
        loadImage = view.findViewById(R.id.id_refresh_image);
        loadTextView = view.findViewById(R.id.id_refresh_text);
        animationDrawable = (AnimationDrawable) loadImage.getBackground();
        animationDrawable.start();
    }

    @Override
    public int getViewHeight() {
        return UIUtils.dpToPx(50);
    }

    @Override
    public void onHintPullDown(int oldState) {
        loadTextView.setText("下拉刷新");
        animationDrawable.start();
    }

    @Override
    public void onHintReleaseHand() {
        loadTextView.setText("松手开始加载");
//        animationDrawable.stop();
    }

    @Override
    public void onRefreshStart() {
        loadTextView.setText("加载中");
//        animationDrawable.start();
    }

    @Override
    public void onRefreshEnd() {
        loadTextView.setText("加载结束");
        animationDrawable.stop();
    }

    @Override
    public void onHeight(int height) {

    }

    @Override
    public void destroy() {
        //清除动画
        loadImage.clearAnimation();
        animationDrawable.stop();
        animationDrawable = null;

    }

    @Override
    public void setHintText(HintText mHintText) {

    }
}
